// 程序入口
class LayaAir3D {

    private scene:Laya.Scene;
    private camera:Laya.Camera;
    private dirLight:Laya.DirectionLight;

    constructor() {
        //初始化微信小游戏
        Laya.MiniAdpter.init();
        //初始化引擎
        Laya3D.init(600, 800, true);

        //适配模式
        Laya.stage.scaleMode = Laya.Stage.SCALE_FULL;
        Laya.stage.screenMode = Laya.Stage.SCREEN_NONE;

        //开启统计信息
        Laya.Stat.show();

        this.init();
    }

    private init():void
    {
        //添加3D场景
        this.scene = Laya.stage.addChild(new Laya.Scene()) as Laya.Scene;

        //添加照相机
        this.camera = (this.scene.addChild(new Laya.Camera(0, 0.1, 100))) as Laya.Camera;
        this.camera.transform.translate(new Laya.Vector3(0, 2, 3));
        this.camera.transform.rotate(new Laya.Vector3(-30, 0, 0), true, false);
        this.camera.clearColor = null;

        //添加方向光
        this.dirLight = this.scene.addChild(new Laya.DirectionLight()) as Laya.DirectionLight;
        this.dirLight.color = new Laya.Vector3(0.6, 0.6, 0.6);
        this.dirLight.direction = new Laya.Vector3(1, -1, 0);

        //添加自定义模型
        var box: Laya.MeshSprite3D = this.scene.addChild(new Laya.MeshSprite3D(new Laya.BoxMesh(1, 1, 1))) as Laya.MeshSprite3D;
        //box.transform.rotate(new Laya.Vector3(0, 45, 0), false, false);
        var material: Laya.StandardMaterial = new Laya.StandardMaterial();
        material.diffuseTexture = Laya.Texture2D.load("res/layabox.png");
        box.meshRender.material = material;
        box.addComponent(ScaleAndRotate);
    }
}
new LayaAir3D();